home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9167 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  45 lines

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: To find the class of an object ??
  5. Date: 29 Feb 1996 00:43:33 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4h2srl$8dj@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe3.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 27, 1996 17:22:46 in article <To find the class of an object ??>,
  15. 'didier@cln46ib (Didier BOLF)' wrote: 
  16.  
  17.  
  18. >I have a class A and a class B. The class B inherit the class A. 
  19. >I have too: A tab[MAX];  
  20. >In tab, I put objets of class A or B. 
  21. >How compare two objects of tab to know if they are of the same class ?? 
  22. >and which class they belong to ?? 
  23. If your compiler supports RTTI -- and many older ones do not -- you can 
  24. use the typeid operator.  Read your online docs for more info.   
  25.  
  26. If not, then you can define virtual functions for each of your 
  27. classes; for example: 
  28.  
  29. class Base 
  30.  { 
  31.      virtual const char * TypeOf() const { return "Base"; } 
  32.   ...}; 
  33.  
  34. class Derived 
  35.  { 
  36.      virtual const char * TypeOf() const { return "Derived"; } 
  37.  
  38. -- 
  39. Pete Grant 
  40. Kalevi, Inc. 
  41. Software Engineering & development
  42.